#ifndef ITEM_H
#define ITEM_H

#include <QtCore/QList>
#include <QtGui/QPixmap>
#include "delement.h"

class Item
{
public:
	Item() : parentItem(NULL), pixmap(QPixmap(24,24)) {}
	virtual bool load(const QDomElement& e) =0;
	virtual ~Item() { qDeleteAll(childItems); }
	
	//information on the hierarchy
	Item *child(int i) { return  childItems.value(i); }
	Item *parent() { return parentItem; }
	void appendChild(Item *item);
	int childCount() { return childItems.count(); }
	int row() { return parentItem ? parentItem->childItems.indexOf(this) : 0; } 

	//information on self
	virtual QString displayName() const =0;
	virtual QPixmap getPixmap() const { return pixmap; }
	virtual QString toolTip() const =0;
	virtual QString statusTip() const =0;
	virtual QString whatsThis() const =0;

protected:
	QPixmap pixmap;

private:
	Item *parentItem;
	QList<Item*> childItems;

	//Since there is a constructor,
	//the copy constructor is default to be disabled
	//Disable assign operator.
	Item& operator=(const Item&);
};

class ListItem : public Item
{
public:
	ListItem() {}
	virtual ~ListItem() {}

	virtual bool load(const QDomElement& e);

	//information on list itself
	QString displayName() const { return mDisplayName; }
	QString toolTip() const { return mToolTip; }
	QString statusTip() const { return mStatusTip; }
	QString whatsThis() const { return mWhatsThis; }

private:
	QString mDisplayName;  //the Name which is shown in the TreeView
	QString mToolTip;
	QString mStatusTip;
	QString mWhatsThis;
};

class AdapterDElement : public Item
{
public:
	AdapterDElement():de(NULL){};
	~AdapterDElement(){ if (de) delete de; };
	virtual bool load(const QDomElement& e);

	QString displayName() const { return de->displayName(); }
	QString toolTip() const { return de->toolTip(); }
	QString statusTip() const { return de->statusTip(); }
	QString whatsThis() const { return de->whatsThis(); }

	DElement* getDElement() const { return de; }

private:
	DElement *de;
};

#endif // ITEM_H
